package com.hl.servlet;

import com.alibaba.fastjson.JSON;
import com.hl.bean.PanghuShop;
import com.hl.dao.StoreDao2;
import com.hl.dao.impl.StoreDaoImpl2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
//修改门店的连接
@WebServlet("/shop/modifyShop")
public class UpdateStoreServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("shopId"));
        String shopName = req.getParameter("shopName");
        String shopDescribe = req.getParameter("shopDescribe");
        String shopPhone = req.getParameter("shopPhone");
        String shopProvince = req.getParameter("shopProvince");
        String shopCity = req.getParameter("shopCity");
        String shopDistrict = req.getParameter("shopDistrict");
        String shopAddress = req.getParameter("shopAddress");
        String shopLatitude = req.getParameter("shopLatitude");
        String shopLongitude = req.getParameter("shopLongitude");
        PanghuShop shop = new PanghuShop(id,shopName,shopDescribe,"",shopPhone,shopProvince,shopCity,shopDistrict,shopAddress,shopLongitude,shopLatitude,1,0,"","",0,0);
        StoreDao2 storeDao2 = new StoreDaoImpl2();
        int row = storeDao2.updateStore(shop);
        Map<String,Object> map = new HashMap<>();
        if (row > 0){
            map.put("code",200);//更新成功
        }else {
            map.put("code",300);//更新失败
        }
        resp.getWriter().write(JSON.toJSONString(map));
    }
}
